%{
#include "grammar.hh"
//#define RETURN(tok)  { printf("returning %s (%d)\n",# tok,tok); return tok; }
#define RETURN(tok)    return tok;
int    yyg_line_no=1;
static char * return_string=0;
%}

%option  noyywrap nounput

DIGIT  [0123456789]
ALPHA  [A-Za-z]
ALNUM  [A-Za-z0-1]
%%
^#.*\n                 // comments ignore !!
^"//":*$              // comments ignore !!
\n+                   yyg_line_no++; RETURN(T_NEWLINE);
:                     RETURN(T_SEMICOLON);
{DIGIT}+"."{DIGIT}*   yylval.constant_double=atof(yytext); RETURN(T_DOUBLE);
{DIGIT}+              yylval.constant_double=atof(yytext); RETURN(T_DOUBLE);
"+"                   RETURN('+');
"-"                   RETURN('-');
"/"                   RETURN('/');
"*"                   RETURN('*');
"("                   RETURN('(');
")"                   RETURN(')');
";"                   RETURN(';');
","                   RETURN(',');
"="                   RETURN('=');
">"                   RETURN('>');
"<"                   RETURN('<');
"=="                  RETURN(T_EQUAL_EQUAL);
"<="                  RETURN(T_LESS_EQUAL);
">="                  RETURN(T_GREATER_EQUAL);
"!="                  RETURN(T_NOT_EQUAL);
"<>"                  RETURN(T_NOT_EQUAL);
print                 RETURN(T_PRINT);
if                    RETURN(T_IF);
then                  RETURN(T_THEN);
and                   RETURN(T_AND);
or                    RETURN(T_OR);
not                   RETURN(T_NOT);
else                  RETURN(T_ELSE);
endif                 RETURN(T_END_IF);
end                   RETURN(T_END);
for                   RETURN(T_FOR);
to                    RETURN(T_TO);
next                  RETURN(T_NEXT);
\"[^"]*\"             return_string=strdup(yytext+1); return_string[strlen(return_string)-1]=0; yylval.constant_literal=return_string; RETURN(T_LITERAL);
{ALPHA}{ALNUM}*       return_string=strdup(yytext); yylval.constant_literal=return_string; RETURN(T_IDENTIFIER);
.                     /* ignore */
